package cn.tedu.spring.di;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 在UserService类中,注入UserDao对象;
 */
@Service
public class UserService {
    @Value("Lucy")
    private String username;
    /*
        Autowired注解：自动装配注解;
        1.作用：注入对象类型或者接口类型的数据;
        2.添加位置:
          2.1 添加在属性上;
          2.2 添加在set方法上;
          2.3 添加在构造方法上;
        Value注解添加位置：
          1.添加在属性上;
          2.添加在set方法上;
     */
    @Autowired
    private UserDao userDao;

    //@Value("Tom")
    public void setUsername(String username) {
        this.username = username;
    }

    //@Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    //@Autowired
    public UserService(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public String toString() {
        return "UserService{" +
                "username='" + username + '\'' +
                ", userDao=" + userDao +
                '}';
    }
}
